package com.fh.auth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:
 * @author： qiujunda
 * @date： 2020/12/18 10:13
 */
@Component
public class BlackWhiteListHandler {

    @Autowired
    private BlackWhiteListConf blackWhiteListConf;


    boolean validateBlackList(ServerHttpRequest serverHttpRequest){
        if(!blackWhiteListConf.isOpenBlack()){
            return true;
        }
        List<BlackWhiteList> list=blackWhiteListConf.getBlackLists();
        for(BlackWhiteList li :list){
            if(BlackWhiteListValidatorFactory.getDefualt().validate(serverHttpRequest,li)){
                return false;
            }
        }
        return true;
    }
    boolean validateWhiteList(ServerHttpRequest serverHttpRequest){
        if(!blackWhiteListConf.isOpenWhite()){
            return true;
        }
        List<BlackWhiteList> list=blackWhiteListConf.getWhiteLists();
        for(BlackWhiteList li :list){
            if(BlackWhiteListValidatorFactory.getDefualt().validate(serverHttpRequest,li)){
                return true;
            }
        }
        return false;
    }
}
